package com.yanftch.hdc_tools.command

import com.yanftch.hdc_tools.common.MessageDelegate
import com.yanftch.hdc_tools.common.executeCommand
import com.yanftch.hdc_tools.common.finalCommandLine
import com.yanftch.hdc_tools.common.isCommandSucceed

class KillProcessCommand : Command {
    override fun run(commandContext: CommandContext): Boolean {
        with(commandContext) {
            try {
                val executeCommand = executeCommand(finalCommandLine(hdcPath, force_stop, bundleName))
                if (executeCommand.isCommandSucceed()) {
                    MessageDelegate.info("stop process success.", action)
                } else {
                    MessageDelegate.error("stop process failed. $executeCommand", action)
                }
            } catch (e: Exception) {
                e.printStackTrace()
                MessageDelegate.error("KillProcessCommand error: ${e.message}", action)
            }
        }
        return false
    }
}